import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static int[][] arr;
    public static int n;
    public static List<Integer> list = new ArrayList<>();
    public static int pathS = 1; //酸度
    public static int pathB = 0; //苦度

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();

        //arr[0]表示酸度，arr[1]表示苦度
        arr = new int[2][n];
        for (int i = 0; i < n; i++) {
            arr[0][i] = sc.nextInt();
            arr[1][i] = sc.nextInt();
        }

        dfs(0, pathS, pathB);

        int ret = Integer.MAX_VALUE;

        for (int i : list) {
            ret = Math.min(ret, i);
        }
        System.out.println(ret);

        sc.close();
    }

    public static void dfs(int pos, int pathS, int pathB) {

        if (pos != 0 && !(pathS == 1 && pathB == 0)) {//刚开始进来不统计
            list.add(Math.abs(pathS - pathB));
        }

        if (pos == n) {
//            if (pathS == 1 && pathB == 0) { //一个都没选
//                list.remove(list.size() - 1);
//            }
            return;
        }

//        System.out.println(pathS + ", " + pathB);

        //选
        dfs(pos + 1, pathS * arr[0][pos], pathB + arr[1][pos]);

        //不选
        dfs(pos + 1, pathS, pathB);
    }
}
